package rainQuality.dao.impl;

import rainQuality.dao.BaseDao;
import rainQuality.dao.RainManageDao;
import rainQuality.entity.RainManage;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RainManageDaoImpl extends BaseDao implements RainManageDao {
    @Override
    public List<RainManage> select() {
        List<RainManage> list=new ArrayList<>();
        ResultSet rs=null;
        try {
            String sql="select * from rainquality";
            rs=super.executeQuery(sql,null);
            while (rs.next()){
                RainManage rainManage=new RainManage();
                rainManage.setId(rs.getInt(1));
                rainManage.setName(rs.getString(2));
                rainManage.setDate(rs.getString(3));
                rainManage.setRain(rs.getString(4));
                rainManage.setStati(rs.getString(5));
                rainManage.setAdd(rs.getString(6));
                list.add(rainManage);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }

    @Override
    public int sc(String id) {
        int count=0;
        String sql="delete from rainquality where id=?";
        Object[] pampt={id};
        count=super.executeUpdate(sql,pampt);
        if(count>0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
        return count;
    }

    @Override
    public int Xz(RainManage rainManage) {
        int count=0;
        String sql="insert into rainquality(districtName,monitorTime,rain,monitoringStation,monitoringAddress)\n" +
                "values(?,?,?,?,?)";
        Object[] pampt={rainManage.getName(),rainManage.getDate(),rainManage.getRain(),
                rainManage.getStati(),rainManage.getAdd()};
        count=super.executeUpdate(sql,pampt);
        System.out.println(count);
        if(count>0){
            System.out.println("新增成功");
        }else{
            System.out.println("新增失败");
        }
        return count;
    }
}
